package com.lq.ecoldchain.ui.withdraw

import android.content.Intent
import android.view.View
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.lq.ecoldchain.R
import com.lq.ecoldchain.base.BaseNavigator
import com.lq.ecoldchain.base.view.BaseActivity
import com.lq.ecoldchain.callback.SafeClickListener
import com.lq.ecoldchain.databinding.ActivityWithdrawBinding
import com.lq.ecoldchain.entity.BankCardEntity
import org.kodein.di.Kodein
import org.kodein.di.generic.instance

/*
*2019/1/6 0006  14:49
*function by lq
*/
@Route(path = BaseNavigator.withdraw)
class WithdrawActivity : BaseActivity<ActivityWithdrawBinding>() {
    override val layoutId = R.layout.activity_withdraw
    override val viewDelegate: WithdrawDelegate  by instance()
    @Autowired
    @JvmField
    var money:String?="1"

    override fun initView() {
        ARouter.getInstance().inject(this)
        binding.delegate = viewDelegate
        titleText("提现")
        rightText("提现记录", object : SafeClickListener() {
            override fun onNoDoubleClick(v: View) {
                ARouter.getInstance().build(BaseNavigator.withdrawHistory).navigation()
            }
        })
        viewDelegate.viewModel.realmoney.value = money
        viewDelegate.viewModel.money.value ="余额剩余${money}元"
    }

    override val kodein = Kodein.lazy {
        extend(parentKodein)
        import(withdrawKodeinModule)
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode == RESULT_OK && requestCode == viewDelegate.withdrawRequestCode) {
            val entity = data?.getParcelableExtra<BankCardEntity>("data")
            if(entity!=null){
                viewDelegate.viewModel.bankName.value = entity.bankName
                viewDelegate.viewModel.bankId.value = entity.id.toString()
                viewDelegate.viewModel.bankNo.value = entity.bankNo
            }
        }
    }


}